﻿using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;
using Sentio.CodeReview.Foundation;

namespace Sentio.CodeReview.Editor
{
    [Export(typeof(IWpfTextViewMarginProvider))]
    [Name(CodeReviewStatusControlBar.MarginName)]
    [Order(After = PredefinedMarginNames.Top)]
    [MarginContainer(PredefinedMarginNames.Top)]
    [ContentType("text")]
    [TextViewRole(PredefinedTextViewRoles.Document)]
    internal sealed class CodeReviewStatusControlBar : IWpfTextViewMarginProvider
    {
        public const string MarginName = "CodeReviewStatusControlBar";

        public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin marginContainer)
        {
            Microsoft.VisualStudio.Text.ITextDocument document = null;
            document = wpfTextViewHost.TextView.TextDataModel.DocumentBuffer.Properties[typeof(Microsoft.VisualStudio.Text.ITextDocument)]
                        as Microsoft.VisualStudio.Text.ITextDocument;
            if (document != null || document.TextBuffer != null)
            {
                return new CodeReviewStatusControlMargin(document.FilePath);
            }
            return null;
        }
    }
}
